

package com.hazelcast.jet.impl.connector;

import com.hazelcast.function.BiFunctionEx;
import com.hazelcast.function.BinaryOperatorEx;
import com.hazelcast.function.FunctionEx;
import com.hazelcast.jet.pipeline.DataConnectionRef;

/**
 * Parameters for using a map as a sink
 */
public class MapSinkConfiguration<T, K, V> {

    private final String mapName;

    private DataConnectionRef dataConnectionRef;
    private String clientXml;

    private FunctionEx<? super T, ? extends K> toKeyFn;
    private FunctionEx<? super T, ? extends V> toValueFn;
    private BiFunctionEx<? super V, ? super T, ? extends V> updateFn;
    private BinaryOperatorEx<V> mergeFn;

    public MapSinkConfiguration(String mapName) {
        this.mapName = mapName;
    }

    public String getMapName() {
        return mapName;
    }

    public DataConnectionRef getDataConnectionRef() {
        return dataConnectionRef;
    }

    public void setDataConnectionRef(DataConnectionRef dataConnectionRef) {
        this.dataConnectionRef = dataConnectionRef;
    }

    public String getDataConnectionName() {
        return dataConnectionRef == null ? null : dataConnectionRef.getName();
    }

    public String getClientXml() {
        return clientXml;
    }

    public void setClientXml(String clientXml) {
        this.clientXml = clientXml;
    }

    public boolean isRemote() {
        return dataConnectionRef != null || clientXml != null;
    }

    public FunctionEx<? super T, ? extends K> getToKeyFn() {
        return toKeyFn;
    }

    public void setToKeyFn(FunctionEx<? super T, ? extends K> toKeyFn) {
        this.toKeyFn = toKeyFn;
    }

    public FunctionEx<? super T, ? extends V> getToValueFn() {
        return toValueFn;
    }

    public void setToValueFn(FunctionEx<? super T, ? extends V> toValueFn) {
        this.toValueFn = toValueFn;
    }

    public BiFunctionEx<? super V, ? super T, ? extends V> getUpdateFn() {
        return updateFn;
    }

    public void setUpdateFn(BiFunctionEx<? super V, ? super T, ? extends V> updateFn) {
        this.updateFn = updateFn;
    }

    public BinaryOperatorEx<V> getMergeFn() {
        return mergeFn;
    }

    public void setMergeFn(BinaryOperatorEx<V> mergeFn) {
        this.mergeFn = mergeFn;
    }

}
